package jdbc;


import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Scanner;

public class LoginUserDemo {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        System.out.println("欢迎来到用户登录");
        System.out.print("请输入用户名:");
        String name = scan.next();
        System.out.print("请输入密码:");
        String pwd = scan.next();

        try (Connection conn = DBUtil.getConnection();) {
            String sql = "SELECT id,username,password,age " +
                    "FROM userinfo " +
                    "WHERE username = '" + name + "' AND password = '" + pwd + "'";
            Statement st = conn.createStatement();
            ResultSet rs = st.executeQuery(sql);
            System.out.println(rs.next() ? "登录成功" : "登录失败");


        } catch (SQLException e) {
            throw new RuntimeException(e);
        }

    }
}
